home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / INPUT.PAK / DISPATCH.C next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.5 KB  |  116 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   dispatch.c
  9. //
  10. //  PURPOSE:  Implement the generic message dispatcher.
  11. //    
  12. //
  13. //  FUNCTIONS:
  14. //    DispMessage - Call the function associated with a message.
  15. //    DispDefault - Call the appropriate default window procedure.
  16. //
  17. //  COMMENTS:
  18. //
  19.  
  20. #include <windows.h>            // required for all Windows applications
  21. #include <windowsx.h>
  22. #ifdef WIN16
  23. #include "win16ext.h"           // required only for win16 applications
  24. #endif
  25. #include "globals.h"            // prototypes specific to this application
  26.  
  27. LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
  28.  
  29. //
  30. //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
  31. //
  32. //  PURPOSE: Call the function associated with a message.
  33. //
  34. //  PARAMETERS:
  35. //    lpmsdi - Structure containing the message dispatch information.
  36. //    hwnd - The window handle
  37. //    uMessage - The message number
  38. //    wparam - Message specific data
  39. //    lparam - Message specific data
  40. //
  41. //  RETURN VALUE:
  42. //    The value returned by the message function that was called.
  43. //
  44. //  COMMENTS:
  45. //    Runs the table of messages stored in lpmsdi->rgmsd searching
  46. //    for a message number that matches uMessage.  If a match is found,
  47. //    call the associated function.  Otherwise, call DispDefault to
  48. //    call the default function, if any, associated with the message
  49. //    structure.  In either case, return the value recieved from the
  50. //    message or default function.
  51. //
  52.  
  53. LRESULT DispMessage(LPMSDI lpmsdi, 
  54.                     HWND   hwnd, 
  55.                     UINT   uMessage, 
  56.                     WPARAM wparam, 
  57.                     LPARAM lparam)
  58. {
  59.     int  imsd;
  60.  
  61.     MSD *rgmsd = lpmsdi->rgmsd;
  62.     int  cmsd  = lpmsdi->cmsd;
  63.  
  64.     for (imsd = 0; imsd < cmsd; imsd++)
  65.     {
  66.         if (rgmsd[imsd].uMessage == uMessage)
  67.             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
  68.     }
  69.  
  70.     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
  71. }
  72.  
  73.  
  74. //
  75. //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
  76. //
  77. //  PURPOSE: Call the appropriate default window procedure.
  78. //
  79. //  PARAMETERS:
  80. //    edwp - Enumerate specifying the appropriate default winow procedure.
  81. //    hwnd - The window handle
  82. //    uMessage - The message number
  83. //    wparam - Message specific data
  84. //    lparam - Message specific data
  85. //
  86. //  RETURN VALUE:
  87. //    If there is a default proc, return the value returned by the
  88. //    default proc.  Otherwise, return 0.
  89. //
  90. //  COMMENTS:
  91. //    Calls the default procedure associated with edwp using the specified
  92. //    parameters.
  93. //
  94.  
  95. LRESULT DispDefault(EDWP   edwp, 
  96.                     HWND   hwnd, 
  97.                     UINT   uMessage, 
  98.                     WPARAM wparam, 
  99.                     LPARAM lparam)
  100. {
  101.     switch (edwp)
  102.     {
  103.         case edwpNone:
  104.             return 0;
  105.         case edwpWindow:
  106.             return DefWindowProc(hwnd, uMessage, wparam, lparam);
  107.         case edwpDialog:
  108.             return DefDlgProc(hwnd, uMessage, wparam, lparam);
  109.         case edwpMDIFrame:
  110.             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
  111.         case edwpMDIChild:
  112.             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
  113.     }
  114.     return 0;
  115. }
  116.